#!/usr/bin/env python
# -*- coding: utf-8 -*-

from tools_karkkainen_sanders import *
from suffix_array import *
from rstr_max import *
from string import *
import sys

limit_recur = sys.getrecursionlimit()
sys.setrecursionlimit(limit_recur*limit_recur)
def test(str1,str2):
	str1_unicode = unicode(str1,'utf-8','replace')
	str2_unicode = unicode(str2,'utf-8','replace')
        relevantcontent=[]
	rstr = Rstr_max()
	rstr.add_str(str1_unicode)
	rstr.add_str(str2_unicode)
	array_repeated = rstr.go()

#	print "str length nb_occur"
	for r in array_repeated :
	  first_suffix = rstr.get_suffix(r[1][0])
	  global_str = rstr.get_str(first_suffix[2])
	  l = first_suffix[0] + r[0]
	  s = global_str[first_suffix[0]:l].encode('utf-8', 'replace')
	  set_str_occur = set()
	  for id_suffix in r[1] :
	    suffix = rstr.get_suffix(id_suffix)
	    set_str_occur.add(suffix[2])
#	  print "    ", set_str_occur
	  if(len(set_str_occur) == 2) :
	#    pass
	#    print "[%s] %d %d"%(s, r[0], len(r[1])) 
            relevantcontent.append(s)
	#  for id_su in r[1] :
        #print relevantcontent
	return relevantcontent
        #    suffix = rstr.get_suffix(id_su)
	#    str_corres = rstr.get_str(suffix[2])
	#    foreach($rstr[1] as $id_su){
	#      $suffix = $factory_rstr->__get_suffix($id_su);
	#      $str_correspondante  = $factory_rstr->__get_str($suffix[2]);
	#      echo "  string $suffix[2] - offset $suffix[0] - lenght $rstr[0]\n";
	#    }
